from urllib.request import *
from fake_useragent import *
from urllib.error import *

# 处理URL异常

url = "http://httpbin.org/get123"

headers = {
    "User-agent": UserAgent().chrome
}
try:
    request = Request(url, headers=headers)
    response = urlopen(request)
    print(response.read().decode())
except HTTPError and URLError as e:
    # HTTPError
    if e.args:
        print("HTTPError")
    # URLError
    elif e.code == 404:
        print("URLError")
